package coding;

public class Manager
{
	private static MonsterHunter[] hunters;
    private static Monster[] monsters;
    private static int hunterCount;
    private static int monsterCount;
    
    public Manager()
	{
		hunterCount = 0;
		monsterCount = 0;
		int numOfHunter = 1;
		int numOfMonster = 5;

		for (int i=0;i<numOfHunter;i++)
			createMonsterHunter("");
		for (int i=0;i<numOfMonster;i++)	
			createMonster();

		Battle battle = new Battle(this);
	}

    public Manager(String userChoice)
    {
        hunterCount = 0;
        monsterCount = 0;
        int numOfHunter = 1;
        int numOfMonster = 5;

        for (int i=0;i<numOfHunter;i++)
            createMonsterHunter(userChoice);
        for (int i=0;i<numOfMonster;i++)    
            createMonster();

        Battle battle = new Battle(this);
    }
    
    public static void createMonsterHunter(String userChoice)
    {
        if (hunterCount>0)
        {
	        MonsterHunter[] temp = new MonsterHunter[hunterCount];
	        for(int i=0;i<hunterCount;i++)
	            temp[i] = hunters[i];
	        hunters = new MonsterHunter[hunterCount+1];
	        for(int i=0;i<hunterCount;i++)
	            hunters[i] = temp[i];
        }
        else if (hunterCount==0)
            hunters = new MonsterHunter[hunterCount+1];

        hunters[hunterCount]=CreationManager.createMonsterHunter(userChoice, hunterCount);
        hunterCount++;
    }
    
    public static void createMonster()
    {
        if (monsterCount>0)
        {
	        Monster[] temp = new Monster[monsterCount];
	        for(int i=0;i<monsterCount;i++)
	            temp[i] = monsters[i];
	        monsters = new Monster[monsterCount+1];
	        for(int i=0;i<monsterCount;i++)
	            monsters[i] = temp[i];
        }
        else if (monsterCount==0)
            monsters = new Monster[monsterCount+1];

        monsters[monsterCount]=CreationManager.createMonster(monsterCount);
        monsterCount++;
    }
    
    public static boolean destroyMonsterHunter(MonsterHunter h)
    {
        if (hunterCount<=0)
            return false;
        else
        {
            int i=0,j=0;
            MonsterHunter[] temp = new MonsterHunter[hunterCount-1];
            for (;i<hunterCount;i++)
            {
                if (hunters[i] != h)
                {
                    temp[j] = hunters[i];
                    j++;
                }
            }
            hunters = temp;
            hunterCount--;
            
            return true;
        }
    }
    
    public static boolean destroyMonster(Monster m)
    {
        if (monsterCount<=0)
            return false;
        else
        {
            int i=0,j=0;
            Monster[] temp = new Monster[monsterCount-1];
            for (;i<monsterCount;i++)
            {
                if (monsters[i] != m)
                {
                    temp[j] = monsters[i];
                    j++;
                }
            }
            monsters = temp;
            monsterCount--;
                
            return true;
        }
    }
    
    public static int getHunterCount()
    {
        return hunterCount;
    }
    
    public static int getMonsterCount()
    {
        return monsterCount;
    }
    
    public static MonsterHunter[] getHuntersList()
    {
        return hunters;
    }
    
    public static Monster[] getMonstersList()
    {
        return monsters;
    }
}